package com.iot.ic.tcp;

import com.iot.ic.controller.LocationController;
import com.iot.ic.model.Location;
import com.iot.ic.tcp.model.MsgRequest;
import com.iot.ic.tcp.model.MsgResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 自定义任务分配工具类，根据设备发过来的
 * 
 * @author xiuge 2016年10月9日下午4:43:50
 */
@Component
public class CustomDispatcher {

	private Logger logger= LoggerFactory.getLogger(CustomDispatcher.class);

	@Autowired
	private LocationController locationController;

	public MsgResponse dispatch(MsgRequest request) {
		if (!request.getChecked()) {//校验未通过
			return null;
		}
		MsgResponse response=null;
		List<Location> locationList=request.getLocations();
		for (Location location:locationList) {
			Integer result=locationController.uploadLocation(location);
			if (result!=null&&result==1)
				logger.info("插入位置信息"+location);
		}
		System.out.println("接收的数据是："+response);
		return response;
	}
}
